home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
GameKit
/
Headers
/
gamekit
/
GameView.h
< prev
next >
Wrap
Text File
|
1995-06-12
|
6KB
|
147 lines
// A generic class used to handle lots of the logic found in a game like
// pausing, misc. states, backgrounds, etc. It has
// rudimentary key and mouse handling methods; it's up to a subclass to
// define them further as is appropriate.
#import <appkit/appkit.h>
#define GKKEYCODE (myevent->data.key.charCode)
#define BEZELSIZE 8.0 // width of the bezel border...
#define GRANULARITY 0.05 // timer granularity. Screen should be updated
#define CYCLES 1 // every 0.05 sec., so here, 2*0.025 = 0.05
#define SPEEDUP 20 // how often to speed up game (every x columns)
#define INITCY 8 // initial colCycles = INITCY * CYCLES
// kinds of key events passed to the player object
#define GK_ALL_KEYUP 0 // passed to "release all keys" (view loses focus)
#define GK_KEYDOWN 1
#define GK_KEYUP 2
// directions
#define GK_NO_DIRECTION -1
#define GK_LEFT_DIRECTION 3
#define GK_RIGHT_DIRECTION 1
#define GK_UP_DIRECTION 0
#define GK_DOWN_DIRECTION 2
#define GK_NORTHEAST_DIRECTION 4
#define GK_NORTHWEST_DIRECTION 5
#define GK_SOUTHEAST_DIRECTION 6
#define GK_SOUTHWEST_DIRECTION 7
// left here for compatability's sake with older versions
#define LEFT GK_LEFT_DIRECTION
#define RIGHT GK_RIGHT_DIRECTION
#define UP GK_UP_DIRECTION
#define DOWN GK_DOWN_DIRECTION
#define NORTHEAST GK_NORTHEAST_DIRECTION
#define NORTHWEST GK_NORTHWEST_DIRECTION
#define SOUTHEAST GK_SOUTHEAST_DIRECTION
#define SOUTHWEST GK_SOUTHWEST_DIRECTION
// states -- tells autoUpdate what to do; a subclass of this view would add
// whatever it needs in the way of new states.
#define NORMALSTATE 0 // player's pill dropping
#define GAMEOVER 1 // things still blink, etc.
#define WAITFORDEMO 600 // Wait x cycles before gameover to start demo
// 600 cycles is approx. 30 sec, more or less.
@interface GameView:View
{
id backGround;
id scoreKeeper; // tracks player's score
id strings; // localized strings
id customSound; // call to handle the sounds
id preferences; // PreferencesBrain
id dirtPile; // Object to handle flushing
id buffer; // screen buffer
id staticBuffer; // screen buffer holds maze, etc.
id controller; // Game controller (GameBrain) reports level, etc.
id animator; // Animator instance
id listenerId; // Grabs Workspace messages for drag and drop.
int state; // current state
int cycles; // used to blink things, etc. -- counts frames
int demoWait; // how many cycles to wait before demo
char keys[5]; // keys to play game
BOOL paused; // game is paused if == YES
BOOL grayBorder; // == YES if gray border is on
BOOL doingBorder; // == YES if turning border on/off
BOOL demoMode; // keep brain from putting demo score as high
BOOL backIsColor;
NXColor backColor;
NXDragOperation dragOperation;
NXPoint offset; // holds x/y offset of "real drawing area" allows
// drawing machinery to deal with scrolling windows over a
// much larger play area, or a view which is larger than the
// play area, and draw the play area as an inset...
}
// initialization and start up functions
- initFrame:(const NXRect *)frm; // initialize instance
- appDidInit:sender; // forwarded by gamebrain
- loadPix; // gameBrain calls this from appDidInit
- animate:sender; // start animation-call from appDidInit
// return info about game state and so on...
- (int)gameState; // returns current state
- (int)realGameState; // tell caller our state...may need to really know...
- (BOOL)demoMode; // if last game was demo or in demo now
- (float)speedTime; // returns current speed
- (BOOL)isPaused; // tell caller if we're paused
- autoUpdate:sender; // sent by timer
- pause:sender; // pause game
- unpause:sender; // unpause game
- getPreferences; // set up preference inst. variables
- getOffset:(NXPoint *)aPoint; // returns offset by reference
- setOffset:(const NXPoint *)aPoint; // change the offset
// various view methods; many are overridden from the default NeXTstep
// methods... basically, deal with various event types.
- (BOOL)acceptsFirstResponder; // to grab keyboard events
- updateSelf:(NXRect *)rects :(int)rectCount; //used by internals for speed
- (BOOL)acceptsFirstMouse; // let us grab activating mousedowns
- mouseDown:(NXEvent *)event; // handle mouseDown events.
- keyDown:(NXEvent *)myevent; // handle keyDown events.
- setKey:(int)keyIndex val:(char)keyVal; // change key we respond to
- setUpScreen; // set up the game screen
- changeBorder:(BOOL)borderOn; // move view about in the window & do sizing
- restartGame; // reset internal variables to restart level
// background handling methods. Set various files, render the background,
// resize it, and deal with drag and drop colors. The specific background
// stuff comes from BreakApp; the color stuff and any modifications are mine.
- setBackgroundFile:(const char *)fileName andRemember:(BOOL)remember;
- buildBackground; // allows hook to add static stuff on top of image
- changeBackground:sender;
- revertBackground:sender;
- sizeTo:(NXCoord)width :(NXCoord)height;
- loadAnImage:(const char *)imageName;
- back1:sender;
- back2:sender;
- back3:sender;
- drawBackground:(NXRect *)rect;
// Note: although this is an "obsolete" API in 3.0, it's OK because
// I use the new 3.0 drag and drop methods (as I should) and then
// have them call this when appropriate. Note that NEXTSTEP no
// longer does that, however; I do it explicitly! So in the GameKit,
// it is NOT obsolete...it is supported. :)
- acceptColor:(NXColor)color atPoint:(const NXPoint *)aPoint;
- writeColor;
// rebuild staticBuffer
- rebuildStaticBuffer;
- rebuildStaticAt:(NXRect *)rect;
// drag & drop images & color
- (NXDragOperation)draggingEntered:sender;
- (NXDragOperation)draggingUpdated:sender;
- draggingExited:sender;
- (BOOL)prepareForDragOperation:sender;
- (BOOL)performDragOperation:sender;
- concludeDragOperation:sender;
- gameOver; // sent by GameBrain
@end